#coding=utf-8
__author__ = 'zhulehao'
import os,MySQLdb,re
path = os.path.split(os.path.realpath(__file__))[0]+"/"
f = open(path+"code.txt","r")
A = f.read()
db = MySQLdb.connect("127.0.0.1","root","","0002" )
cursor=db.cursor()
arr=re.split("\s+",A)
cursor.execute("DROP TABLE IF EXISTS CODE")
# sql = ""CREATE TABLE CODE (
#          num INT,
# 		content text
# 		 )""
cursor.execute("""CREATE TABLE CODE(
         num INT,
		content text
		 )""")
try:
    for i in range(len(arr)):
        if i:
            cursor.execute('insert into code (num,content) values("%s","%s")' % (i,arr[i]))
            print cursor.rowcount
            # sql="""INSERT INTO `CODE` SET `no`=%s,`content`='%s'"""%(i,arr[i])
            # cursor.execute(sql)
    db.commit()
except Exception as e:
    print e
    db.rollback()